#ifndef INDEXPAGE_H
#define INDEXPAGE_H

#include <QWidget>
#include <QHash>
#include <QThread>
#include <QTimer>
#include <QDateTime>
#include "../remoteservice/productinfo.h"
#include "../remoteservice/scheduleinfo.h"

namespace Ui {
class IndexPage;
}

class ShadeWidget;
class IndexPageWorker;

class IndexPage : public QWidget
{
    Q_OBJECT
    
public:
    explicit IndexPage(QWidget *parent = 0);
    ~IndexPage();

    void loadSchedule();

signals:
    void updateSchedule();

protected:
    void showEvent(QShowEvent *e);
    bool eventFilter(QObject *o, QEvent *e);

private slots:

    void productInfoSlot(ProductInfo);
    void refreshSchedule(LIST_SCHEDULES list);

    void receiveSchedule(ScheduleInfo);

    void resetUi();

    void callSlot(BaseResp);

    void checkUpdates();

    void timerHandle();

private:
    void afterShowEvent();
    void initFocusOrder();

    void call(QString number,QString name);

    void caculateDuration();
    
private:
    Ui::IndexPage *ui;
    QWidget *m_contentWidget;
    QHash<QObject*, QList<QObject*> > m_ctrlOrder;  //<控件,<控件上下左右方向上的控件>>，方位上没有控件设置为NULL
    QObject *currentItem;
    bool hasShade;          //是否绘制了遮罩窗口
    ShadeWidget *m_shadeWidget;
    int m_originalHeight;

    QThread workThread;
    IndexPageWorker *worker;
    QTimer m_timer;
    QString m_confNum;
    int m_curposition;
    int m_currentCount;
    QDateTime m_today;
    uint m_seconds;

    QTimer m_calendar_timer;
};

#endif // INDEXPAGE_H
